package com.test08.excelpoi04;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.gson.Gson;

import jxl.Sheet;
import jxl.Workbook;
import jxl.format.CellFormat;
import jxl.write.Boolean;
import jxl.write.DateFormats;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

/*
 * 用来处理1.xls中的站点中信息的类
 * 
 */
public class ExcelTest02<V> {
	public static <E> void main(String[] args) throws Exception {
		// 构建Workbook对象, 只读Workbook对象
		InputStream instream = new FileInputStream("src/1.xls");
		Workbook readwb = Workbook.getWorkbook(instream);
		// 得到一个可写的副本及sheet
		WritableWorkbook writableWorkbook = Workbook.createWorkbook(new File("src/1.xls"), readwb);// 创建workbook的副本
		WritableSheet writableSheet = writableWorkbook.getSheet(0);
		// 得到最大行数和列数
		int rsColumns = writableSheet.getColumns();
		int rsRows = writableSheet.getRows();
		// 开始从上向下遍历
		String contents;
		WritableCell writableCell;
		CellFormat cellFormat;
		Label label;
		for (int i = 3; i < rsRows; i++) {
			for (int j = 8; j < rsColumns; j++) {
				switch (j) {
				case 8:
				case 9:
				case 10:
				case 11:
				case 12:
					try {
						writableCell = writableSheet.getWritableCell(j, i);
						// 得到原值
						contents = writableCell.getContents().trim();
						if(!"".equals(contents)) {
							// 写回去
							cellFormat = writableCell.getCellFormat();
							label = new Label(j, i, ExcelTest04.convert(new Double(contents)).toString());
							label.setCellFormat(cellFormat);
							writableSheet.addCell(label);
						}
					} catch (Exception e) {
					}
					break;
				default:
					break;
				}
			}
		}
		writableWorkbook.write();
		writableWorkbook.close();// 关闭workbook，释放内存 ---》一定要释放内存
	}

}
